package cn.ktp.demo.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fescar.core.context.RootContext;
import com.alibaba.nacos.api.config.annotation.NacosValue;

import cn.ktp.demo.dao.DemoDao;
import cn.ktp.demo.iservice.IDemoService;

@Service
@com.alibaba.dubbo.config.annotation.Service
public class DemoService implements IDemoService {

	@Autowired
	DemoDao dao;

	@NacosValue(value = "${test.testValue:test}", autoRefreshed = true)
	String testValue;

	@Override
	public void demo() {
		System.out.println("全局事务id ：" + RootContext.getXID());
		dao.insert();
	}

	@Override
	public String nacosValueDemo() {
		return "这是nacos的动态配置testValue，值为：" + testValue;
	}

	@Override
	public String testTransaction() {
		dao.insert();
		if (1 == 1) {
			throw new RuntimeException("bbb");
		}
		dao.insert();
		return null;
	}

}
